Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
How do I click a javascript "link" using rselenium to start downloading excel file?

I'm a beginner in R and I've been trying to scrape the following website:

https://sinca.mma.gob.cl/cgi-bin/APUB-MMA/apub.htmlindico2.cgi?page=pageFrame&header=Las%20Condes&macropath=./RM/D13/Cal/0001&macro=0001.diario.diario&from=970508&to=090312&

to automatically start downloading an excel file from this air monitoring station here in Chile. However, I noticed that using SelectorGadget the download link couldn't be selected and found out it was because the link was a javascript link (href="javascript:Open('xcl');">Excel CSV) as seen in the image below.

enter image description here

My question is there any way I can simulate a click on that javascript link? I've already simulated clicks for other parts of the same website succesfully but they where not javascript links. This is what I've already tried:

library(rvest)
library(RSelenium)


rD <- rsDriver(browser="firefox", port=4040L, verbose=F)
remDr <- rD[["client"]]


remDr$open()
remDr$navigate("https://sinca.mma.gob.cl/cgi-bin/APUB-MMA/apub.htmlindico2.cgi?page=pageFrame&header=Las%20Condes&macropath=./RM/D13/Cal/0001&macro=0001.diario.diario&from=970508&to=090312&")
Sys.sleep(5) # give the page time to fully load


# click on excel link to start downloading file (doesnt work) ------------

xls <- remDr$findElement("xpath", "/html/body/table/tbody/tr/td/table[2]/tbody/tr[1]/td/label/span[3]/a")
xls$clickElement()
/html/body/table/tbody/tr/td/table[2]/tbody/tr[1]/td/label/span[3]/a


##### TESTING

remDr$navigate("https://sinca.mma.gob.cl/cgi-bin/APUB-MMA/apub.htmlindico2.cgi?page=pageFrame&header=Las%20Condes&macropath=./RM/D13/Cal/0001&macro=0001.diario.diario&from=970508&to=090312&")
excel <- remDr$findElement(using = "css selector", "[href*=javascript]")
#excel <- remDr$findElement(using = "css selector", '[href*="javascript:Open('xcl')"]')
excel$highlightElement() # to visually check what elemnet is selected


remDr$closeServer()
remDr$close()

My objective is to be able to click the link and start downloading the excel file. I've been trying to do this for a couple days and I'm stuck, so any help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is inside a frame that is inside a frameset. You first need to switch to that frame via the parent frameset, using RSelenium. You can use the frame ids frMain and right to target the elements to switch to. Then you should be able to simply target that href by using a css attribute = value selector of [href*=xcl]. The * is the contains operator specifying that the href attribute value of the target contains the substring xcl.

Something like the following (not tested):

frame_set <- remDr$findElement("css", "#frMain")
remDr$switchToFrame(frame_set)

child_frame <- remDr$findElement("css", "#right")
remDr$switchToFrame(child_frame)

csv_download <- remDr$findElement(using = "css", "[href*=xcl]")
csv_download$clickElement()

You can use browser dev tools F12 to view that path:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda